<?php

namespace ctrl\demo;

use L;

class amazon
{
    //http://ec.com/?c=demo_amazon&a=pull //测试亚马逊接口
    public static function pull()
    {
        /*
        $sql = "SELECT `oauth` FROM account WHERE id = 35";
        $row = L::sql($sql);
        $oauth = json_decode($row[0]['oauth'], true);
        */
        $string = '{"id": "35", "ip": "43.132.164.4:9444", "site": "US", "region": "us-east-1", "endpoint": "sellingpartnerapi-na.amazon.com", "client_id": "amzn1.application-oa2-client.e784be74cf6640068891e92a34c56456", "access_key": "ASIA2FFEOUAKGJHNISOH", "secret_key": "Z0kCJxQ8+1NgsbLU8CniNN81ajhN9MzSpDO9KGO9", "merchant_id": "A35GO8FU480JZH", "access_token": "Atza|IwEBIJ4cDylLClSc5wsM_tkXJjHr9UNoO_CGLYUPnVS4zBNSZ-F4xHUL_3ODEzzjitgF7mrxoUdr6x7PKZviSGAOnGmMeqk_bVYXIesB0nbQchW6wUeMphE6I9P1NogpzDJNk8ZfxTAaZNbz00qD3SZ-de7ZO2Z2keHHp7XTCc7YJ2KPZEi19AUczCvb9vWWEnwvuuAHSu3pP13t5YK4dRLY83kLvUmOm_E2WzFLHH8YOpNuGgnrvIG0Xqj6mMxfiDkjh0pzfdEu81wxgHQJUuEdJMZWDMV_8qP-7k9aR5LJnXPsSzdXhMrAh_PLdSWU2cLh6aiU71RBOENm8SY5ZLkbcRtl", "aws_role_arn": "arn:aws:iam::698277077012:role/AutelOnline", "client_secret": "amzn1.oa2-cs.v1.460713ae351ffa9c6ed3f30e95b00739b56ae5e552ea75162fa0c76259bfa9ce", "refresh_token": "Atzr|IwEBIMEHHtp2mD-JZLc3Ay_CFsf9Q8SCC7gINm2BM5EIvbZArLCkMYrlkqgiY-hRZlZDVV51lcZPSlgnD3OCbME5MqjelmjpOJsnEl4VW5rttjcG_pD4ikmVB7zEKhv1sYnNx-ECcrFkbUF3L_hV_K2too0T_b7plNEOd7heroTIF25WMY0up93KSOsxisQXAgC_bYB7J4cWBLY_62nGeQK8U_9eZW0JhnYA-ZWHM2jqtqWMB9LR7X9tW9rXi3DU4r3xE-Qr5YB2MID2DsrM99IxTfcexSLizr2LlzVhpHjixcV2bxoK75qaImYhUOOurL1gJGI", "session_token": "FwoGZXIvYXdzEBkaDCAejYNbLMizoBTRUSKsAUjBbEUQ53BxUz4ejgLOEqbzRcJz4nELYHD7uCBggZjFQxempepl+f8Y+NTBvhqaVqBgh9uNGHiEbuhtYEOCM7cg11n1Rs40SU8/NQQhWpKNLem4WW/smxpsGJSu/ByK6m00yEtmHshJJLxgTzzkUvVq86zlsNFPClmHBNKlTjRYmfxGyFsj4vSWqAslDLA/1uBXvHF6hqDgdZiMC+RCM6rweNU9ETw3tCUryZsowbfYtAYyLQWnv4iZFGumjV6oYMO5iqtdNIWYCkn/FRCjWW33x0SV6v2fPsDgbFIdXJX1gg==", "aws_access_key": "AKIA2FFEOUAKCDXOLX7T", "aws_secret_key": "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", "marketplace_id": "ATVPDKIKX0DER"}';
        $oauth = json_decode($string, true);
        $client = new \Sdk\Amazon\Api\FbaInventory($oauth);
        $queryParams = [
            'granularityType' => 'Marketplace',
            'granularityId' => $client->marketplaceId,
            'marketplaceIds' => $client->marketplaceId,
            'details' => 'true',
            'nextToken' => ""
        ];
        $request = $client->getInventorySummaries($queryParams);
        echo '<pre>';
        var_dump($request);
    }
}
